extends Control

@onready var label = $Panel/Label
var tween: Tween

func _ready():
	visible = false

func show_message(text: String, duration: float = 3.0):
	label.text = text
	visible = true
	
	# 停止之前的动画
	if tween:
		tween.kill()
	
	# 创建淡入淡出动画
	tween = create_tween()
	tween.set_parallel(true)
	
	# 淡入
	modulate.a = 0.0
	tween.tween_property(self, "modulate:a", 1.0, 0.3)
	
	# 延迟后淡出
	tween.tween_property(self, "modulate:a", 0.0, 0.5).set_delay(duration - 0.5)
	
	# 动画完成后隐藏
	tween.tween_callback(func(): visible = false).set_delay(duration)